package jp.eisbahn.mgapi.auth;

import java.io.IOException;

import javax.servlet.http.HttpServletResponse;

/**
 * This class has an ability to navigate a user to the page
 * for an authorization.
 * @author Yoichiro Tanaka
 */
public class Authorization {

    /**
     * Redirect user to the page to authorize.
     * @param response The response object.
     * @param config The configuration object.
     * @param scopes The scope array which your application want to access.
     * @param display The display type of the authorization screen.
     * @param device The device the user uses.
     * @throws IOException If some errors occurred while the redirecting.
     */
    public final void redirect(final HttpServletResponse response,
            final ClientConfig config, final String[] scopes,
            final String display, final Device device) throws IOException {
        String url = new AuthorizationUrlBuilder()
                .setClientConfig(config)
                .setScopes(scopes)
                .setDisplay(display)
                .setDevice(device)
                .build();
        response.sendRedirect(url);
    }

}
